package com.hardydou.jmm;


/**
 * 死锁示例代码
 *
 * @author hardy
 */
public class DeadLock extends Thread {

    String lockA;
    String lockB;

    public DeadLock(String threadName, String lockA, String lockB) {
        super(threadName);
        this.lockA = lockA;
        this.lockB = lockB;
    }

    public void doSomeThing() {
        synchronized (lockA) {
            System.out.println("holding  " + lockA + " wait for " + lockB);
            try {
                Thread.sleep(50L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (lockB) {
                System.out.println("DeadLock.doSomeThing");
            }
        }

    }


    public void run() {
        doSomeThing();
    }


}
